//
//  UIViewController+DebugMode.m
//  CPSecurityTools
//
//  Created by collegepre on 2019/11/15.
//  Copyright © 2019 collegepre. All rights reserved.
//

#import "UIViewController+DebugMode.h"
#import <objc/runtime.h>
#import "CPDebugConfigViewController.h"
@implementation UIViewController (DebugMode)
+ (void)load {
    #ifdef DEBUG
        //do sth.
      Method viewWillAppear1 = class_getInstanceMethod(self, @selector(viewDidLoad));
      //需要替换成 能够输出日志的viewWillAppear
      Method logViewWillAppear1 = class_getInstanceMethod(self, @selector(logViewDidLoad:));
      //两方法进行交换
      method_exchangeImplementations(viewWillAppear1, logViewWillAppear1);
    #else
        //do sth.
    #endif
  
}

- (void)logViewDidLoad:(BOOL)animated {
    NSLog(@"Current method: %@,%@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
    
    //下面方法的调用，其实是调用viewWillAppear
    UILongPressGestureRecognizer *pan = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pangesture:)];
    pan.numberOfTouchesRequired = 3;
    [self.view addGestureRecognizer:pan];
    [self logViewDidLoad:animated];
}

- (void)pangesture:(UILongPressGestureRecognizer *)pan{
    if (pan.state == UIGestureRecognizerStateBegan) {
        CPDebugConfigViewController *vc = [[CPDebugConfigViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
        vc.title = @"项目环境配置";
        [self presentViewController:nav animated:YES completion:^{
            
        }];
    }
}

@end
